<?php
/**
 * Defines the edges cubies
 *
 * @package Cube
 * @since   Oct 19, 2006
 * @author  Christophe Thiriot
 */

jClasses::inc('cube~Cubie');

/**
 * The class of the edges
 *
 * @package Cube
*/
class Edge extends Cubie 
{
    const MAX_EDGE = 12;

    /**
     * @var integer
     */
    private $orientation;

    /**
     * Constructor
     */
    public function __construct($opos, $orient = 0) 
    {
        parent::__construct(parent::EDGE);
        if (is_numeric($opos) && $opos <= self::MAX_EDGE && $opos >= 0) 
        {
        	$this->originPosition = $opos;
        } else 
        {
        	throw new Exception('Edge::__construct : Bad edge origin position');
        }
        if ($orient === 0 || $orient === 1) 
        {
            $this->orientation = $orient;
        } else 
        {
            throw new Exception('Edge::__construct : Bad edge orientation');
        }
    }

    /**
     * getter
     * @final
     */
    public function getOrientation() 
    {
        return $this->orientation;
    }

    /**
     * Change the state of orientation between 0 (oriented) and 1 (not oriented)
     */
    public function toggleOrientation() 
    {
        if ($this->getOrientation() === 0) 
        {
        	$this->orientation = 1;
        } else 
        {
            $this->orientation = 0;
        }
    }

    /**
     * generates the string representing the orientation
     */
    public function orientToString() 
    {
        if ($this->getOrientation() === 0) 
        {
            return '';
        } elseif ($this->getOrientation() === 1) 
        {
            return '-';
        } else 
        {
            throw new Exception('Edge::orientToString : bad orientation');
        }
    }
}
?>
